Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@turf/meta
Advanced tools
@turf/meta is a module of the Turf.js library that provides utility functions for working with GeoJSON data. It allows you to iterate over various GeoJSON objects, extract specific properties, and manipulate geometries.
coordEach
The `coordEach` function iterates over each coordinate in any GeoJSON object, allowing you to perform operations on each coordinate.
const turf = require('@turf/meta');
const point = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [110, 50] } };
turf.coordEach(point, function (coord) {
console.log(coord);
});
propEach
The `propEach` function iterates over properties in any GeoJSON Feature or FeatureCollection, allowing you to access and manipulate properties.
const turf = require('@turf/meta');
const featureCollection = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "A" }, "geometry": { "type": "Point", "coordinates": [110, 50] } } ] };
turf.propEach(featureCollection, function (properties, featureIndex) {
console.log(properties);
});
geomEach
The `geomEach` function iterates over each geometry in any GeoJSON object, allowing you to perform operations on each geometry.
const turf = require('@turf/meta');
const featureCollection = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [110, 50] } } ] };
turf.geomEach(featureCollection, function (geometry, featureIndex) {
console.log(geometry);
});
The `geojson-utils` package provides utility functions for manipulating and analyzing GeoJSON data. It offers similar functionalities to @turf/meta, such as iterating over coordinates and geometries, but it also includes additional features like distance calculations and point-in-polygon tests.
The `geolib` package is a library for geospatial calculations. While it does not focus specifically on GeoJSON, it provides a wide range of geospatial utilities, including distance calculations, bounding box operations, and coordinate transformations. It can be used in conjunction with GeoJSON data for various geospatial tasks.
The `geojson-extent` package is designed to calculate the bounding box of GeoJSON objects. While it does not offer the same breadth of functionality as @turf/meta, it is useful for specific tasks related to determining the spatial extent of GeoJSON data.
Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (currentCoords, currentIndex)excludeWrapCoord
[boolean] whether or not to include
the final coordinate of LinearRings that wraps the ring in its iteration. (optional, default false
)Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.coordEach(features, function (currentCoords, currentIndex) {
//=currentCoords
//=currentIndex
});
Reduce coordinates in any GeoJSON object, similar to Array.reduce()
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (previousValue, currentCoords, currentIndex)initialValue
[Any] Value to use as the first argument to the first call of the callback.excludeWrapCoord
[boolean] whether or not to include
the final coordinate of LinearRings that wraps the ring in its iteration. (optional, default false
)Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.coordReduce(features, function (previousValue, currentCoords, currentIndex) {
//=previousValue
//=currentCoords
//=currentIndex
return currentCoords;
});
Returns Any The value that results from the reduction.
Iterate over properties in any GeoJSON object, similar to Array.forEach()
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (currentProperties, currentIndex)Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {"foo": "bar"},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {"hello": "world"},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.propEach(features, function (currentProperties, currentIndex) {
//=currentProperties
//=currentIndex
});
Reduce properties in any GeoJSON object into a single value, similar to how Array.reduce works. However, in this case we lazily run the reduction, so an array of all properties is unnecessary.
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (previousValue, currentProperties, currentIndex)initialValue
[Any] Value to use as the first argument to the first call of the callback.Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {"foo": "bar"},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {"hello": "world"},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.propReduce(features, function (previousValue, currentProperties, currentIndex) {
//=previousValue
//=currentProperties
//=currentIndex
return currentProperties
});
Returns Any The value that results from the reduction.
Iterate over features in any GeoJSON object, similar to Array.forEach.
Parameters
Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.featureEach(features, function (currentFeature, currentIndex) {
//=currentFeature
//=currentIndex
});
Reduce features in any GeoJSON object, similar to Array.reduce().
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (previousValue, currentFeature, currentIndex)initialValue
[Any] Value to use as the first argument to the first call of the callback.Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {"foo": "bar"},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {"hello": "world"},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.featureReduce(features, function (previousValue, currentFeature, currentIndex) {
//=previousValue
//=currentFeature
//=currentIndex
return currentFeature
});
Returns Any The value that results from the reduction.
Get all coordinates from any GeoJSON object.
Parameters
layer
Object any GeoJSON objectExamples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
var coords = turf.coordAll(features);
//=coords
Returns Array<Array<number>> coordinate position array
Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (currentGeometry, currentIndex)Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.geomEach(features, function (currentGeometry, currentIndex) {
//=currentGeometry
//=currentIndex
});
Reduce geometry in any GeoJSON object, similar to Array.reduce().
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (previousValue, currentGeometry, currentIndex)initialValue
[Any] Value to use as the first argument to the first call of the callback.Examples
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {"foo": "bar"},
"geometry": {
"type": "Point",
"coordinates": [26, 37]
}
},
{
"type": "Feature",
"properties": {"hello": "world"},
"geometry": {
"type": "Point",
"coordinates": [36, 53]
}
}
]
};
turf.geomReduce(features, function (previousValue, currentGeometry, currentIndex) {
//=previousValue
//=currentGeometry
//=currentIndex
return currentGeometry
});
Returns Any The value that results from the reduction.
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this module individually:
$ npm install @turf/meta
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf meta module
The npm package @turf/meta receives a total of 967,818 weekly downloads. As such, @turf/meta popularity was classified as popular.
We found that @turf/meta demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.